﻿/*
 * Created by SharpDevelop.
 * User: Andrew Sadler
 * Date: 06/09/2012
 * Time: 22:27
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Globalization;
using System.IO;
using System.Threading;

using RRRSRoguelikeData;

namespace RRRSRoguelike.Helpers
{
	/// <summary>
	/// Description of Language.
	/// </summary>
	public class Language
	{
		//Possibly belongs in a helper class
		public static void NewLanguage(string culture)
		{
			//Set Properties
			Properties.Settings.Default.Culture = culture;
			//Set Culture
			Thread.CurrentThread.CurrentUICulture =
			CultureInfo.GetCultureInfo(Properties.Settings.Default.Culture);
			//Set Custom Folder path
			Properties.Settings.Default.CustomFolder =
				Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
							 "RRRSRoguelike", "CustomContent", Properties.Settings.Default.Culture);

			Properties.Settings.Default.Save();

			PrepareContentFolder(AppDomain.CurrentDomain.BaseDirectory);

		}

		public static void PrepareContentFolder(string baseDir)
		{
			//Prepare Custom Content Folder

			var sourcePath = Path.Combine(baseDir,
											 "CustomContent",
											 Properties.Settings.Default.Culture);

			if (!Directory.Exists(sourcePath))
			{
				sourcePath = Path.Combine(baseDir,
										  "CustomContent", "en-US");
			}

			string targetPath;

			if (Properties.Settings.Default.CustomFolder == "-1")
			{
				targetPath = Path.Combine(Environment.GetFolderPath(
					Environment.SpecialFolder.MyDocuments), "RRRSRoguelike", "CustomContent");
				Properties.Settings.Default.CustomFolder = targetPath;
			}
			else
			{
				targetPath = Properties.Settings.Default.CustomFolder;
			}

			Files.CopyFolder(sourcePath, targetPath, false);
		}
	}
}
